package com.kehutong.charge.service.impl;

import com.kehutong.charge.entity.ChargeBillConfig;
import com.kehutong.charge.service.ChargeBillConfigService;
import org.coraframework.inject.Inject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.util.Objects;

import java.util.List;

/**
 * 账单配置
 *
 * @author wupengfei
 */
public class ChargeBillConfigServiceImpl implements ChargeBillConfigService {

    private static final Logger logger = LoggerFactory.getLogger(ChargeBillConfigServiceImpl.class);

    @Inject
    private JdbcSession jdbcSession;

    @Override
    public ChargeBillConfig get(String communityNo, String billYearMonth) {
        logger.info("获取账单配置communityNo=" + communityNo + ",billYearMonth=" + billYearMonth);
        List<ChargeBillConfig> billConfigs = jdbcSession.findArray(ChargeBillConfig.class).eq("communityNo", communityNo).eq("billYearMonth", billYearMonth)
                .order("createTime", "desc").exe();
        return Objects.isEmpty(billConfigs) ? null : billConfigs.get(0);
    }

    @Override
    public void delete(String communityNo, String billYearMonth) {
        logger.info("删除账单配置communityNo=" + communityNo + ",billYearMonth=" + billYearMonth);
        jdbcSession.delete(ChargeBillConfig.class).eq("communityNo", communityNo).eq("billYearMonth", billYearMonth).exe();
    }
}
